package com.example.mybatis.one2one.dao;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import com.example.mybatis.one2one.domain.B;
import com.example.mybatis.utils.MyBatisUtils;

public class BDao {
	private Logger logger = Logger.getLogger(BDao.class.getName());
	
	public void addB(B b){
		if(b == null){
			return;
		}
		SqlSession session = MyBatisUtils.getSqlSession();
		try {
			session.insert(B.class.getName()+".addB", b);
			session.commit();
		} catch(Exception e){
			session.rollback();
			logger.warn(e);
		} finally {
			MyBatisUtils.closeSqlSession(session);
		}
	}
	
	public B getById(Integer id){
		SqlSession session = MyBatisUtils.getSqlSession();
		System.out.println("b:" + session);
		try {
			return session.selectOne(B.class.getName()+".getById",id);
		} finally {
			MyBatisUtils.closeSqlSession(session);
		}
	}
}
